package com.gx.mxbbx.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gx.mxbbx.dao.TotalMapper;
import com.gx.mxbbx.po.Disease;
import com.gx.mxbbx.po.Reimbursement;
import com.gx.mxbbx.service.TotalService;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional
public class TotalServiceImpl implements TotalService {
    @Autowired
    private TotalMapper totalMapper;

    public PageInfo<Reimbursement> getTotalList(String fullName, String countyId, Integer currentPage, Integer limit) {
        PageHelper.startPage(currentPage, limit);
        List<Reimbursement> list = totalMapper.getTotalList(fullName, countyId);
        PageInfo<Reimbursement> pageInfo = new PageInfo<Reimbursement>(list);
        return pageInfo;
    }

    public XSSFWorkbook show() {
        List<Reimbursement> list = totalMapper.selectByExample();//查出数据库数据
        XSSFWorkbook wb = new XSSFWorkbook();
        Sheet sheet = wb.createSheet("Goods");//创建一张表
        org.apache.poi.ss.usermodel.Row titleRow = sheet.createRow(0);//创建第一行，起始为0
        titleRow.createCell(0).setCellValue("id");//第一列
        titleRow.createCell(1).setCellValue("县级编号");
        titleRow.createCell(2).setCellValue("农合证号");
        titleRow.createCell(3).setCellValue("医疗证卡号");
        titleRow.createCell(4).setCellValue("姓名");
        titleRow.createCell(5).setCellValue("性别");
        titleRow.createCell(6).setCellValue("身份证号");
        titleRow.createCell(7).setCellValue("年龄");
        titleRow.createCell(8).setCellValue("报销时间");
        titleRow.createCell(9).setCellValue("慢性病名称");
        titleRow.createCell(10).setCellValue("需要报销金额");
        titleRow.createCell(11).setCellValue("报销余额");
        titleRow.createCell(12).setCellValue("实际报销金额");
        titleRow.createCell(13).setCellValue("慢性病证号");
        titleRow.createCell(14).setCellValue("电话号");
        titleRow.createCell(15).setCellValue("状态");
        int cell = 1;
        for (Reimbursement reimbursement : list) {
            Row row = sheet.createRow(cell);//从第二行开始保存数据
            row.createCell(0).setCellValue(cell);
            row.createCell(1).setCellValue(reimbursement.getCountyId());//将数据库的数据遍历出来
            row.createCell(2).setCellValue(reimbursement.getPeasantId());
            row.createCell(3).setCellValue(reimbursement.getMedicalCare());
            row.createCell(4).setCellValue(reimbursement.getFullName());
            row.createCell(5).setCellValue(reimbursement.getSex());
            row.createCell(6).setCellValue(reimbursement.getIdentityCard());
            row.createCell(7).setCellValue(reimbursement.getYear());
            row.createCell(8).setCellValue(reimbursement.getCreateTime());
            row.createCell(9).setCellValue(reimbursement.getSortName());
            row.createCell(10).setCellValue(reimbursement.getTotalAmount());
            row.createCell(11).setCellValue(reimbursement.getTopAmount());
            row.createCell(12).setCellValue(reimbursement.getRealityAmount());
            row.createCell(13).setCellValue(reimbursement.getDiseaseId());
            row.createCell(14).setCellValue(reimbursement.getTelephone());
            row.createCell(15).setCellValue(reimbursement.getStatus());
            cell++;
        }
        return wb;
    }

}
